<?php include_once "ra_global.php";
if($_POST['cheap_code'] && $_POST['openid']){
	$cheap_code=$db->ig2_want('mae_cheap_code','code='.$_POST['cheap_code']);
	if($cheap_code){
		if($cheap_code['count']<=$cheap_code['get_count']){
			tellgoto('此代码使用已超过规定次数','cheap_code.php');
		}else{
			$value=array('get_count'=>$cheap_code['get_count']+1);
			$db->ig2_update('mae_cheap_code',$value,'id='.$cheap_code['id']);
			$user=$db->ig2_want('mae_user,mae_role','mae_user.id=mae_role.uid and mae_role.is_delete=0 and mae_user.openid="'.$_POST['openid'].'"');
			$value=array(
				'id'			=>'',
				'account_id'	=>16621,
				'cheap_id'		=>$cheap_code['id'],
				'shop_id'		=>$user['shop_id'],
				'uid'			=>$user['uid'],
				'create_time'	=>time()
			);
			$db->ig2_insert('mae_cheap_code_log',$value);
			tellgoto('代码验证成功','cheap_code.php');            
		}
	}else{
		tellgoto('代码不存在','cheap_code.php');
	}
}else{
	tellgoto('查询异常','cheap_code.php');
}
?>